package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {


    // 新增订单
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     *
     * @param number
     */
    @Select("select * from orders where number = #{number}")
    Orders getByNumber(String number);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    // 分页查询
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    // 根据id查询订单
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    // 统计各状态的订单数量
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    // 定时处理超时订单
    @Select("select * from orders where status = 1 and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrderTime(Integer status, LocalDateTime orderTime);

    //统计营业额数据
    Double subByStatusCount(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    //统计订单数
    Integer countByOrderStatus(Map map);

    //统计top10
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);


}
